package com.guang.syncronized.review_day1;

import org.openjdk.jol.info.ClassLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author liguang
 * @Date 2022/10/22/18:26
 */
public class SyncronziedSpecifyThree {
    private final static Logger logger = LoggerFactory.getLogger(SyncronziedSpecifyThree.class);
    public static void main(String[] args) throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        Object object = new Object();
        logger.info("无锁可偏向，101。打印对象头：{}", ClassLayout.parseInstance(object).toPrintable());

        Thread t1 = new Thread(() -> {
            synchronized (object){
                logger.info("偏向锁偏向t1线程，101。打印对象头：{}", ClassLayout.parseInstance(object).toPrintable());
            }
        },"t1");
        t1.start();
        t1.join();

        Thread t2 = new Thread(() -> {
            logger.info("理论上是轻量级锁000，也可能是101。打印对象头：{}", ClassLayout.parseInstance(object).toPrintable());
        },"t2");
        t2.start();


    }
}
